﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Cgd.Shell.Data;
using Cgd.Shell.Utilities;
using System.Text;

public partial class CgdShellMasterPage : ActionlessMasterPage
{
	protected void Page_Load(object sender, EventArgs e)
	{
		SetNavLinks();

		using(CgdShellDataContext db = new CgdShellDataContext())
		{
			lstLinks.DataSource = from link in db.Links
								  where link.Show
								  orderby link.DisplayOrder
								  select link;
			lstLinks.DataBind();
		}
	}

	private void SetNavLinks()
	{
		navDefault.HRef = UrlUtility.GetFullUrl("");
		navNews.HRef = UrlUtility.GetFullUrl("News.aspx");
		navJobs.HRef = UrlUtility.GetFullUrl("Jobs.aspx");
		navTech.HRef = UrlUtility.GetFullUrl("Tech.aspx");
		navDesign.HRef = UrlUtility.GetFullUrl("Design.aspx");
		navDownload.HRef = UrlUtility.GetFullUrl("Download.aspx");
	}

	public void SetActiveNavButton(string name)
	{
		if(name == "navDefault")
			navDefault.Attributes["class"] = "active";
		else if(name == "navNews")
			navNews.Attributes["class"] = "active";
		else if(name == "navJobs")
			navJobs.Attributes["class"] = "active";
		else if(name == "navTech")
			navTech.Attributes["class"] = "active";
		else if(name == "navDesign")
			navDesign.Attributes["class"] = "active";
		else if(name == "navDownload")
			navDownload.Attributes["class"] = "active";
		//else if(name == "navBlog")
		//    navBlog.Attributes["class"] = "active";
	}

	protected string ListRssFeeds()
	{
		StringBuilder sbRss = new StringBuilder();

		foreach (CgdColumn cc in CgdColumn.AllColumns)
		{
			sbRss.AppendFormat("<link rel='alternate' type='application/rss+xml' title='{0}' href='{1}'>",
				cc.Title + " - 中国游戏开发者",
				UrlUtility.GetColumnRssUrl(cc.Name));
		}

		return sbRss.ToString();
	}
}
